#!/bin/sh
# Load functions and variables
. /usr/bin/common

case "$1" in
  linux)
  PROJECT_SANDCASTLE='Linux'
  ;;
  android)
  PROJECT_SANDCASTLE='Android'
  ;;
  *)
  echo "Specify an argument: 'linux' or 'android'"
  exit 1
  ;;
esac

cd /root/android-sandcastle/

# Show ASCII art
"${1}"_logo

CHECKRA1N="$(/usr/bin/checkra1n -cp > pongo_shell.log 2>&1 & echo $!)"
echo 'Please put your device into DFU mode'
sleep 1
while true; do
  if grep -q 'Booting...' pongo_shell.log; then
    echo 'Pongo loaded. Give it a second'
    sleep 2
    break
  fi
  sleep 1
done
sleep 5
blue_echo "Starting $PROJECT_SANDCASTLE..."
if /usr/bin/load-linux ${PROJECT_SANDCASTLE}.lzma dtbpack; then
  done_echo "Done starting $PROJECT_SANDCASTLE."
  enter_to_quit
else
  failed_echo "Failed to start $PROJECT_SANDCASTLE."
fi
